package cn.jhc.service;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;

import cn.jhc.dao.Dao;
import cn.jhc.entity.Article;

@WebServlet("/findAllArticles.do")
public class FindAllArticle extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Article> dataList = new ArrayList<>();

        try {
            dataList = new Dao().findAllArticle();
            
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Gson gson = new Gson();
        String jsonData = gson.toJson(dataList);
        resp.setContentType("application/json");
        resp.getWriter().print(jsonData);

    }
    






}
